package com.by.controller;

import cn.hutool.core.bean.BeanUtil;
import com.by.bean.Supplier;
import com.by.bean.SupplierInquiry;
import com.by.common.bean.PageBean;
import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.common.group.V;
import com.by.service.SupplierInquiryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.xml.transform.Result;
import java.util.List;
@RestController
@Api(tags = "供应商询价")
@RequestMapping("/api")
public class SupplierInquiryController extends BaseController {
    @Autowired
    SupplierInquiryService supplierInquiryService;

    @PostMapping("/supplierInquiry")
    @ApiOperation("保存供应商询价")
    public ResultBean save(@Validated @RequestBody SupplierInquiry supplierInquiry, BindingResult result){
        V.validate(result);
        int rs = supplierInquiryService.save(supplierInquiry);
        return saveResult(rs);
    }

    @ApiOperation(("修改供应商询价"))
    @PutMapping("/supplierInquiry")
    public ResultBean update(@RequestBody SupplierInquiry supplierInquiry){
        int rs = supplierInquiryService.update(supplierInquiry);
        return updateResult(rs);
    }

    @PostMapping("/supplierInquiry/list")
    @ApiOperation("供应商询价列表")
    public ResultBean<PageBean<List<SupplierInquiry>>> query(@RequestBody SupplierInquiry supplierInquiry) {
        PageBean bean = supplierInquiryService.queryByMap(BeanUtil.beanToMap(supplierInquiry));
        return success("查询成功", bean);
    }

}
